Skip to content

fs.readdirSync on a file: ENOTDIR on Windows, not EINVAL - #91

Merged
ASDAlexander77 merged 1 commit into
mainfrom
fix/fs-readdir-enotdir-windows
Nov 11, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
fix/fs-readdir-enotdir-windows

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

What

tslang_fs_read_dir (src/wrappers/os.cpp) now reports ENOTDIR when the path is an existing file that isn't a directory, as Node does.

Why

On Windows, opening a directory iterator on a file fails with ERROR_DIRECTORY, which MSVC's std::system_category maps to EINVAL. tests/fs.ts expects ENOTDIR (or ENOENT) in its "list a file" check, so it failed on every Windows job (EINVAL: invalid argument, scandir '...'). Linux already reports ENOTDIR, so nothing changes there.

Notes for the reviewer

  • Tested locally on Windows, release, -mm=gc, both compiled and under the JIT: fs, process, process_exit, array_flat, map_groupBy and string_fromCodePoint all print ALL DONE.
  • Not run locally: the debug pass (this machine's compiler debug runtime is out of date) and the rc/none/own models on Windows. CI covers those.
  • The Windows jobs on process and fs; Array flat/flatMap/toSpliced, Map.groupBy, String.fromCodePoint #90 ran for over an hour instead of failing. My guess, not confirmed: in the debug pass the failed assert calls abort(), which opens a modal dialog that nobody closes. This fix stops that assert from failing.

🤖 Generated with Claude Code

Windows gives ERROR_DIRECTORY for a directory iterator opened on a file,
which MSVC maps to EINVAL; Node says ENOTDIR. tslang_fs_read_dir now checks
for an existing non-directory when the listing fails and reports ENOTDIR.
fs.ts's "list a file" failed on every Windows job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit e5c170e into main Nov 11, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant